package com.softeem.god.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softeem.god.comm.R;
import com.softeem.god.entity.Album;
import com.softeem.god.entity.Music;
import com.softeem.god.mapper.AlbumMapper;
import com.softeem.god.service.MusicService;
import com.softeem.god.mapper.MusicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 86139
* @description 针对表【music】的数据库操作Service实现
* @createDate 2025-10-28 11:42:48
*/
@Service
public class MusicServiceImpl extends ServiceImpl<MusicMapper, Music>
    implements MusicService{

    @Autowired
    private AlbumMapper albumMapper;

    @Override
    public R musicDetails(Integer id) {
        //根据id查询音乐
        Music m = getById( id);
        if (m == null){
            return R.error().setMsg("没有此音乐");
        }
        if (m.getAid()==null){
            return R.error().setMsg("专辑不存在");
        }
        //根据音乐的所属专属id查询专辑信息
        Album a = albumMapper.selectById(m.getAid());
        //将当前专辑设置给音乐对象
        m.setAlbum(a);
        //返回结果
        return R.success().setData(m);
    }
}




